#include "MLNumGen_Uniform.h"
_MYLABLIB_BEGIN

CMLNumGen_Uniform::CMLNumGen_Uniform(void)
{
	// Standard Uniform Distribution. U(0,1)
	m_vMin.push_back(0.0);
	m_vMax.push_back(1.0);
	m_vPrecise.push_back(1.0/ RAND_MAX);
	m_nNumDimensions = 1;
}

CMLNumGen_Uniform::CMLNumGen_Uniform(const std::vector<double>& vMin, 
																			 const std::vector<double>& vMax)
{
	ML_ASSERT(vMin.size() == vMax.size());

	m_vMin = vMin;
	m_vMax = vMax;
	m_nNumDimensions = (int)vMin.size();
	m_vPrecise.resize(vMin.size());
	int d;
	for (d=0; d<m_nNumDimensions; d++)
	{
		m_vPrecise[d] = (vMax[d] - vMin[d]) / RAND_MAX;
	}
}

CMLNumGen_Uniform::~CMLNumGen_Uniform(void)
{
}

CMLDataPoint CMLNumGen_Uniform::Generate(void)
{
	CMLDataPoint p;
	p.resize(m_nNumDimensions);
	int i;
	for (i=0; i<m_nNumDimensions; i++)
	{
		p[i] = m_vMin[i] + ((double)rand()) * m_vPrecise[i];
	}
	return p;
}

_MYLABLIB_END
